package com.ruoyi.fund.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fund.domain.DmsFund;
import com.ruoyi.fund.service.IDmsFundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资金账户Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-06
 */
@RestController
@RequestMapping("/whole/fund")
public class DmsFundController extends BaseController
{
    @Autowired
    private IDmsFundService dmsFundService;

    /**
     * 查询资金账户列表
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsFund dmsFund)
    {
        startPage();
        List<DmsFund> list = dmsFundService.selectDmsFundList(dmsFund);
        return getDataTable(list);
    }

    /**
     * 导出资金账户列表
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:export')")
    @Log(title = "资金账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsFund dmsFund)
    {
        List<DmsFund> list = dmsFundService.selectDmsFundList(dmsFund);
        ExcelUtil<DmsFund> util = new ExcelUtil<DmsFund>(DmsFund.class);
        util.exportExcel(response, list, "资金账户数据");
    }

    /**
     * 获取资金账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsFundService.selectDmsFundById(id));
    }

    /**
     * 新增资金账户
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:add')")
    @Log(title = "资金账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsFund dmsFund)
    {
        return toAjax(dmsFundService.insertDmsFund(dmsFund));
    }

    /**
     * 修改资金账户
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:edit')")
    @Log(title = "资金账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsFund dmsFund)
    {
        return toAjax(dmsFundService.updateDmsFund(dmsFund));
    }

    /**
     * 删除资金账户
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:remove')")
    @Log(title = "资金账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsFundService.deleteDmsFundByIds(ids));
    }
}
